/*
 * ===========================================================================================
 * = COPYRIGHT
 *          PAX Computer Technology (Shenzhen) Co., Ltd. PROPRIETARY INFORMATION
 *   This software is supplied under the terms of a license agreement or nondisclosure
 *   agreement with PAX Computer Technology (Shenzhen) Co., Ltd. and may not be copied or
 *   disclosed except in accordance with the terms in that agreement.
 *     Copyright (C) 2023 PAX Computer Technology (Shenzhen) Co., Ltd. All rights reserved.
 * ===========================================================================================
 */

import 'package:flutter/material.dart';
import 'package:pos_link/auto_data_source/auto_data_source_common.dart';
import 'package:pos_link/auto_data_source/auto_device_request_data_source.dart';
import 'package:pos_link/auto_data_source/auto_device_response_data_source.dart';
import 'package:pos_link/auto_pigeon/poslink_sdk_device.dart';
import 'package:pos_link/model/response_db.dart';
import 'comm_setting_view_model.dart';

class DeviceViewModel extends ChangeNotifier {
  Future startDevice(ResponseDataBase responseDataBase, List<Map> dataSource) async {
    POSLinkDeviceApi DeviceApi = POSLinkDeviceApi();

    /// command
    Map cmdData = dataSource.first;
    switch (cmdData[kValue]) {
      case DeviceCommand.PrinterRequest:
        DevicePrinterRequest req = DeviceReqData.formPrinterRequest(dataSource);
        DevicePrinterResponse rsp = await DeviceApi.printer(req);
        DeviceRspData.parseRspDevicePrinterResponse(rsp, responseDataBase.deviceData);
        break;
      case DeviceCommand.MifareCardRequest:
        DeviceMifareCardRequest req = DeviceReqData.formMifareCardRequest(dataSource);
        DeviceMifareCardResponse rsp = await DeviceApi.mifareCard(req);
        DeviceRspData.parseRspDeviceMifareCardResponse(rsp, responseDataBase.deviceData);
        break;
      case DeviceCommand.CameraScanRequest:
        DeviceCameraScanRequest req = DeviceReqData.formCameraScanRequest(dataSource);
        DeviceCameraScanResponse rsp = await DeviceApi.cameraScan(req);
        DeviceRspData.parseRspDeviceCameraScanResponse(rsp, responseDataBase.deviceData);
        break;
      case DeviceCommand.CardInsertDetectionRequest:
        DeviceCardInsertDetectionRequest req = DeviceReqData.formCardInsertDetectionRequest(dataSource);
        DeviceCardInsertDetectionResponse rsp = await DeviceApi.cardInsertDetection(req);
        DeviceRspData.parseRspDeviceCardInsertDetectionResponse(rsp, responseDataBase.deviceData);
        break;
      default:
        throw Exception('undefined function');
      //break;
    }
  }
}
